﻿//-----------------------------------------------------------------------
// <copyright file="AssemblyDataContractUnitTest.cs" company="CodePlex">
//     Copyright (c) Doug Holland, CodePlex. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace CodePlex.Diagnostics.Contracts
{
    using System;
    using System.Diagnostics;
    using System.Reflection;
    
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    /// <summary>
    /// Provides unit tests for the <see cref="T:CodePlex.Diagnostics.Contracts.AssemblyDataContract"/> class.
    /// </summary>
    [TestClass]
    public sealed class AssemblyDataContractUnitTest
    {
        #region public AssemblyDataContractUnitTest()

        /// <summary>
        /// Initializes a new instance of the <see cref="T:AssemblyDataContractUnitTest"/> class.
        /// </summary>
        public AssemblyDataContractUnitTest()
        {
        }

        #endregion

        #region public TestContext TestContext

        /// <summary>
        /// Gets or sets the test context which provides information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext
        {
            get;
            set;
        }

        #endregion

        #region public void AssemblyDataContractConstructorUnitTest()

        /// <summary>
        /// Ensures that the constructor of the <see cref="T:CodePlex.Diagnostics.Contracts.AssemblyDataContract"/> class is correctly copying the values from the supplied <see cref="T:System.Reflection.Assembly"/> instance.
        /// </summary>
        [TestMethod]
        public void AssemblyDataContractConstructorUnitTest()
        {
            Assembly executingAssembly = Assembly.GetExecutingAssembly();

            AssemblyDataContract assembly = new AssemblyDataContract(executingAssembly);

            Assert.AreEqual<string>(executingAssembly.CodeBase, assembly.CodeBase, "data contract contains an invalid code base value.");
            
            if (executingAssembly.EntryPoint != null)
            {
                Assert.AreEqual<string>(executingAssembly.EntryPoint.Name, assembly.EntryPoint, "data contract contains an invalid entry point value.");
            }
            else
            {   
                Assert.IsNull(assembly.EntryPoint, "data contract contains an invalid entry point value.");
            }
                        
            Assert.AreEqual<string>(executingAssembly.FullName, assembly.FullName, "data contract contains an invalid full name value.");
            
            Assert.AreEqual<bool?>(executingAssembly.GlobalAssemblyCache, assembly.GlobalAssemblyCache, "data contract contains an invalid global assembly cache value.");
            
            Assert.AreEqual<long?>(executingAssembly.HostContext, assembly.HostContext, "data contract contains an invalid host context value.");
            
            Assert.AreEqual<string>(executingAssembly.ImageRuntimeVersion, assembly.ImageRuntimeVersion, "data contract contains an invalid image runtime version value.");
            
            Assert.AreEqual<string>(executingAssembly.Location, assembly.Location, "data contract contains an invalid location value.");
            
            if (executingAssembly.ManifestModule != null)
            {
                Assert.AreEqual<string>(executingAssembly.ManifestModule.FullyQualifiedName, assembly.ManifestModule, "data contract contains an invalid manifest module value.");
            }
            else
            {
                Assert.IsNull(assembly.ManifestModule, "data contract contains an invalid entry manifest module.");
            }
            
            Assert.AreEqual<bool?>(executingAssembly.ReflectionOnly, assembly.ReflectionOnly, "data contract contains an invalid reflection only value.");

            foreach (object attribute in executingAssembly.GetCustomAttributes(false))
            {
                DebuggableAttribute debuggableAttribute = attribute as DebuggableAttribute;

                if (debuggableAttribute != null)
                {
                    Assert.AreEqual<bool?>(assembly.DebugBuild, debuggableAttribute.IsJITTrackingEnabled, "data contract contains an invalid debug build value.");

                    break;
                }
            }
        }

        #endregion
   }
}
